// JavaScript Document
function getObj(objName){return(document.getElementById(objName));}

var temp;/*菜单ID*/

window.onload =function() {
	var obj=getObj("menu");/*ul的id*/
	var obj_a=obj.getElementsByTagName("a");
	number=obj_a.length;
	for (var i=0,j=obj_a.length;i<j;i++){
		obj_a[i].index=i;
		obj_a[i].className="normal";
		obj_a[i].onclick=function(){click(this)};
		obj_a[i].onmouseover=function(){overme(this)};
		obj_a[i].onmouseout=function(){outme(this)};
		obj_a[i].onfocus=function(){this.blur()};/*去掉IE下的虚线框*/
	}
    if (getCookie("show_a") != null) {
		obj_a[getCookie("show_a")].className="cur";
		temp=getCookie("show_a")
	}
	else{
	    var obj=getObj("menu");
	    var obj_a=obj.getElementsByTagName("a");	    
		obj_a[0].className="cur";	    
	}	
}
//鼠标滑过效果
function overme(o){
    if (temp!=o.index) 
    o.className="over";/*翻滚色样式*/  
}
//鼠标移开后效果
function outme(o){
    if (temp!=o.index) 
    o.className="normal";/*翻滚色样式*/  
}
//鼠标点击效果
function click(o){
   
    var obj=getObj("menu");
	var obj_a=obj.getElementsByTagName("a");
	for (var i=0,j=obj_a.length;i<j;i++){
		obj_a[i].className="normal";
	}
	o.className="cur";
	o.blur();
	setCookie("show_a",o.index,1);/*设置1分钟后失效*/
	temp=o.index 
}
// --- 设置cookie
function setCookie(sName,sValue,expireMinute) {
	var cookieString = sName + "=" + escape(sValue);
	if (expireMinute>0) {//设置过期时间
		 var date = new Date();
		 //date.setTime(date.getTime + expireHours * 3600 * 1000);//时间单位=毫秒,以小时为参数
		 date.setTime(date.getTime + expireMinute * 60 * 1000);//时间单位=毫秒,以分钟为参数
		 
		 cookieString = cookieString + "; expire=" + date.toGMTString();
	}
	document.cookie = cookieString;//写cookie
}
//--- 获取cookie
function getCookie(sName) {
  var aCookie = document.cookie.split("; ");
  for (var j=0; j < aCookie.length; j++){
	var aCrumb = aCookie[j].split("=");
	if (escape(sName) == aCrumb[0])
	  return unescape(aCrumb[1]);
  }
  return null;
}
